class Solution:
    def fullJustify(self, words: list[str], maxWidth: int) -> list[str]:
        from math import ceil
        length = 0
        result = []
        col = []
        for word in words:
            if length+2*len(word)>maxWidth:
                space_num = maxWidth-length
                wwww = ""
                for i in range(len(col)):
                    snum = ceil(space_num/(len(col)-i+1))
                    space_num-=snum
                    wwww += col[i]
                    wwww += ' '*snum
                result.append(wwww)
                length = len(word)
                col = [word]
            else:
                length += len(word)
                col.append(word)
        return result

if __name__ == "__main__":
    s = Solution()
    rs = s.fullJustify(words = ["This", "is", "an", "example", "of", "text", "justification."], maxWidth = 16)
    print(rs)